﻿using System.Collections;

namespace CSharpPro._1020;

public class Demo
{
    public void TestPrint1()
    {
        int[] arr1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
        int[,] arr2 = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
        int[] arr3 = new int[5];
        for (int i = 0; i < arr3.Length; i++)
        {
            arr3[i] = i + 1;
        }

        foreach (int num1 in arr1)
        {
            Console.WriteLine(num1);
        }

        foreach (int num2 in arr3)
        {
            Console.WriteLine(num2);
        }
    }

    public void TestPrint2()
    {
        ArrayList list1 = new ArrayList();
        list1.Add(1);
        list1.Add(2);
        list1.Add(3);
        list1.Add(4);
        list1.Add(5);
        list1.Add(6);
        ArrayList list2 = new ArrayList { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
        foreach (int num1 in list1)
        {
            Console.WriteLine(num1);
        }

        foreach (int num2 in list2)
        {
            Console.WriteLine(num2);
        }
    }

    public void TestPrint3()
    {
        int[] arr = { 11, 23, 66, 33, 56, 29, 88 };
        int n = arr.Length;
        bool swapped;
        for (int i = 0; i < n - 1; i++)
        {
            swapped = false;


            for (int j = 0; j < n - i - 1; j++)
            {
                if (arr[j] > arr[j + 1])
                {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                    swapped = true;
                }
            }

            if (!swapped)
                break;
        }

        foreach (int num in arr)
        {
            Console.Write(num+"\n");
        }
    }
}